module(
    name = "xls",
    repo_name = "com_google_xls",
)

# Compiler toolchain
bazel_dep(name = "toolchains_llvm", version = "1.4.0")

# Configure and register the toolchain.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
    llvm_version = "19.1.7",
)
use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all")

# Python toolchain
# TODO: https://github.com/google/xls/issues/2941 - Update to more recent version once we've
# migrated to Bazel 8.
# We need to pin to 1.0.0 until moving to Bazel 8, or else we run into missing py_library attribute
# (e.g. pyi_srcs) errors in pip dependencies.
bazel_dep(name = "rules_python", version = "1.0.0")

# or-tools otherwise forces us to 1.2.0.
single_version_override(
    module_name = "rules_python",
    version = "1.0.0",
)

PYTHON_VERSION = "3.12"

PYTHON_VERSION_NAME = PYTHON_VERSION.replace(".", "_")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    python_version = PYTHON_VERSION,
)

# Use repo mapping to ensure that BUILD files don't need to be updated when the Python version
# changes to a different version.
use_repo(
    python,
    project_python = "python_{}".format(PYTHON_VERSION_NAME),
    project_python_host = "python_{}_host".format(PYTHON_VERSION_NAME),
)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    timeout = 600000,
    hub_name = "xls_pip_deps",
    python_version = PYTHON_VERSION,
    requirements_lock = "//dependency_support:pip_requirements_lock.txt",
)
use_repo(pip, "xls_pip_deps")

# Root module dependencies.
# Note: some WORKSPACE dependencies still require repo_name aliases.
bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")
bazel_dep(name = "abseil-py", version = "2.1.0")
bazel_dep(name = "bazel_features", version = "1.30.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "boringssl", version = "0.20250114.0")
bazel_dep(name = "cppitertools", version = "2.2")
bazel_dep(name = "googleapis", version = "0.0.0-20240819-fe8ba054a")
bazel_dep(name = "grpc", version = "1.74.1")
bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1")
bazel_dep(name = "or-tools", version = "9.12", repo_name = "com_google_ortools")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "protobuf", version = "31.1", repo_name = "com_google_protobuf")
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")
bazel_dep(name = "riegeli", version = "0.0.0-20250706-c4d1f27")
bazel_dep(name = "rules_cc", version = "0.2.0")
bazel_dep(name = "rules_closure", version = "0.15.0")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "verible", version = "0.0.3933")

# TODO: bazelbuild/bazel-central-registry#1020 - revisit when perfetto is in BCR.
perfetto_ext = use_extension("//dependency_support/perfetto:extension.bzl", "perfetto_extension")
use_repo(perfetto_ext, "perfetto")
use_repo(perfetto_ext, "perfetto_cfg")

# Perfetto requires this to get through bazel analysis, but seems unused for our use.
bazel_dep(name = "rules_android", version = "0.6.0")

# Pin this as otherwise we encounter some bazel analysis failure.
bazel_dep(name = "rules_jvm_external", version = "6.8")

# Pinning some maven versions seems necessary to make things resolve correctly.
# As of 2025-11-07, this seems necessary. If unspecified, junit and mockito have
# some issue with being a testonly dep of a non-test target. I (rigge@) would
# have thought marking them both as an exclusion (like mockito below) would
# solve this, but somehow it didn't for junit. Specifying a specific version of
# junit seems to make things work.
# TODO: bazelbuild/bazel-central-registry#1020 - revisit when perfetto is in BCR.
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
    artifacts = ["junit:junit:4.13.2"],
    known_contributing_modules = [
        "bazel_worker_java",
        "grpc-java",
        "or-tools",
        "rules_closure",
        "rules_web_testing_java",
        "xls",
    ],
)
maven.artifact(
    artifact = "closure-stylesheets",
    exclusions = ["org.mockito:mockito-core"],
    group = "com.google.closure-stylesheets",
    version = "1.5.0",
)

# Used both by XLS and rules_hdl.
bazel_dep(name = "rules_pkg", version = "1.0.1")

# Workaround suggested by a Bazel team member; only needed for WORKSPACE to work correctly.
# TODO: https://github.com/google/xls/issues/931 - Remove this workaround once the WORKSPACE file is migrated to MODULE.bazel.
proto_bazel_features = use_repo_rule("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features")

proto_bazel_features(name = "proto_bazel_features")

# rules_hdl deps with bzlmod support.
bazel_dep(name = "rules_bison", version = "0.3")
bazel_dep(name = "rules_flex", version = "0.3")
bazel_dep(name = "rules_m4", version = "0.3")

# Dev dependencies
bazel_dep(name = "fuzztest", version = "20250805.0", dev_dependency = True, repo_name = "com_google_fuzztest")
bazel_dep(name = "google_benchmark", version = "1.9.4", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.17.0", dev_dependency = True)

# Repositories we don't really depend on directly, but we need to provide
# for other dependencies as they are using old versions that are not
# compatible with current bazel.
bazel_dep(name = "rules_java", version = "8.14.0")
bazel_dep(name = "protoc-gen-validate", version = "1.2.1.bcr.1")

# compilation DB; build_cleaner
bazel_dep(name = "bant", version = "0.2.2", dev_dependency = True)

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
    module_name = "hedron_compile_commands",
    # Updated 2025/08/19.
    commit = "abb61a688167623088f8768cc9264798df6a9d10",
    remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

register_toolchains("//xls/common/toolchains:all")
